/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 

*/

#include "Options.h"

/**
* file   Options.cpp
* date   Jeu 28 jan 2010 18:57:34 CET
* brief  TODO
*/

unsigned short Options::max_upgrades_[NOPTIONS] = {
  1, 1, 3, 5, 1, 1, 1
};
unsigned short Options::nb_credits_[NOPTIONS] = {
  3, 4, 5, 7, 9, 13, 21
};
Uint32 Options::time_limits_[NOPTIONS] = {
  30000,
  30000,
  0,
  0,
  0,
  20000,
  20000
};

OptionState::
OptionState ()
  : current_option_(OPT_NONE), credits_(0) {
}

bool
Option::
request (bool& made_active, const Option* const active_option) {
  // Upgrade already max
  if (upgrade_ == (nupgrades_-1)) {
    made_active = false;
    return false;
  }
  // Option already activated
  if (active_option == this) {
    made_active = false;
    return false;
  }
  // Current active option must be disabled
  // when the current option is also a time-bounded
  // option, except invincibility and crazy ball
  // which are uninterruptible. Note that crazyball
  // cancels invincibility, however it triggers
  // invincibility though.
  // Filter out by upgrade level because
  // time-bounded options always have an upgrade
  // level equal to 1.
  if (nupgrades_ == 1) {
    if (active_option != NULL) {
      if ((active_option->type_ == OPT_ENLARGE) ||
          (active_option->type_ == OPT_STICK)) {
        activate();
        made_active = true;
        return true;
      }
      if ((active_option->type_ == OPT_INVINCIBILITY) &&
          (type_ == OPT_CRAZYBALL)) {
        activate();
        made_active = true;
        return true;
      }
    }
    else {
      activate();
      if (type_ == OPT_SAVE) {
        made_active = false;
      }
      else {
        made_active = true;
      }
      return true;
    }
  }
  else {
    activate();
    made_active = false;
    return true;
  }
}

